package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.system.domain.ConstractBranch;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ConstractInstitute;
import com.ruoyi.system.service.IConstractInstituteService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 总院信息Controller
 * 
 * @author ruoyi
 * @date 2022-04-04
 */
@Controller
@RequestMapping("/system/institute")
public class ConstractInstituteController extends BaseController
{
    private String prefix = "system/institute";

    @Autowired
    private IConstractInstituteService constractInstituteService;

    @RequiresPermissions("system:institute:list")
    @GetMapping("{id}")
    public String institute(@PathVariable("id") Long id, ModelMap mmap)
    {
        mmap.put("constractId", id);
        return prefix + "/institute";
    }

    /**
     * 查询总院信息列表
     */
    @RequiresPermissions("system:institute:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ConstractInstitute constractInstitute)
    {
        startPage();
        List<ConstractInstitute> list = constractInstituteService.selectConstractInstituteList(constractInstitute);
        return getDataTable(list);
    }


    /**
     * 导出总院信息列表
     */
    @RequiresPermissions("system:institute:export")
    @Log(title = "总院信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ConstractInstitute constractInstitute)
    {
        List<ConstractInstitute> list = constractInstituteService.selectConstractInstituteList(constractInstitute);
        ExcelUtil<ConstractInstitute> util = new ExcelUtil<ConstractInstitute>(ConstractInstitute.class);
        return util.exportExcel(list, "总院信息数据");
    }

    /**
     * 新增总院信息
     */
    @GetMapping("/add/{id}")
    public String add(@PathVariable("id") Long id, ModelMap mmap)
    {
        mmap.put("constractId", id);
        return prefix + "/add";
    }

    /**
     * 新增保存总院信息
     */
    @RequiresPermissions("system:institute:add")
    @Log(title = "总院信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ConstractInstitute constractInstitute)
    {
        return toAjax(constractInstituteService.insertConstractInstitute(constractInstitute));
    }

    /**
     * 修改总院信息
     */
    @RequiresPermissions("system:institute:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ConstractInstitute constractInstitute = constractInstituteService.selectConstractInstituteById(id);
        mmap.put("constractInstitute", constractInstitute);
        return prefix + "/edit";
    }

    /**
     * 修改保存总院信息
     */
    @RequiresPermissions("system:institute:edit")
    @Log(title = "总院信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ConstractInstitute constractInstitute)
    {
        return toAjax(constractInstituteService.updateConstractInstitute(constractInstitute));
    }

    /**
     * 删除总院信息
     */
    @RequiresPermissions("system:institute:remove")
    @Log(title = "总院信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(constractInstituteService.deleteConstractInstituteByIds(ids));
    }

    @PostMapping("/details/{id}")
    @ResponseBody
    public TableDataInfo list(@PathVariable("id") Long id)
    {
        ConstractInstitute branch = new ConstractInstitute();
        branch.setConstractId(id);
        startPage();
        return getDataTable(constractInstituteService.selectConstractInstituteList(branch));
    }
}
